package com.example.mapreduce.writableComparable;

/**
 * Created with IntelliJ IDEA.
 * ClassName: FlowMapper
 * Package: com.example.mapreduce.writable
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-15
 * Time: 11:56
 */

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, FlowBean,Text> {

    //选在排序的对象是 FlowBean 但是框架只支持 key 排序 所以输出参数要互换位置

    private FlowBean outK = new FlowBean();
    private Text outV = new Text();


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取一行
        String line = value.toString();

        //进行切割
        String[] split = line.split("\t");

        //封装
        outV.set(split[0]);
        outK.setUpFlow(Long.parseLong(split[1]));
        outK.setDownFlow(Long.parseLong(split[2]));
        outK.setSumFlow();

        //写出
        context.write(outK,outV);

    }
}
